/**
 * 给定一个包含非负整数的数组 nums ，返回其中可以组成三角形三条边的三元组个数。
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        int[]  nums = new int[]{2,2,3,4};
        Solution solution = new Solution();
        int val = solution.triangleNumber(nums);
        System.out.println(val);
    }
}
class Solution {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int cur = nums.length - 1;
        int count = 0;
        while(cur > 1){
            int left = 0;
            int right = cur - 1;
            while(left < right){
                if((nums[left] + nums[right]) > nums[cur]){
                    count += right - left;
                    right--;
                }else{
                    left++;
                }
            }
            cur--;
        }
        return count;
    }
}